package edu.calpoly.android.echoes;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;


public class MyCircle implements MyDrawableShapes {
    Position p;
    Vector2D velocity, direction;
	Paint paint = new Paint();
	
	private int screen;
	
    float radius;
    AudioPlayer ap;
    
	public MyCircle(float x, float y, float r, Paint paint, AudioPlayer ap) {
		p = new Position(x,y);
		radius = r;
		
		this.paint = paint;
		this.ap = ap;
		
		velocity = new Vector2D(0,2);
		direction = new Vector2D((float).707,(float)-.707);
	}
	
	public MyCircle(float x, float y, float r, Vector2D vel, Vector2D dir, Paint paint, AudioPlayer ap) {
		p = new Position(x,y);
		radius = r;
		
		this.paint = paint;

		this.ap = ap;
		
		velocity = vel;
		direction = dir;
	}
	
	public MyCircle(float x, float y, float r, Vector2D vel, Vector2D dir, Paint paint, AudioPlayer ap, int screen) {
		p = new Position(x,y);
		radius = r;
		
		this.paint = paint;

		this.ap = ap;
		
		velocity = vel;
		direction = dir;
		
		this.screen = screen;
	}
	

	public void drawMe(Canvas c) {
		paint.setColor(Color.BLACK);
		
		c.drawCircle(p.getX(), p.getY(), radius, paint);
		
		if(screen == 0)
			paint.setColor(Color.YELLOW);
		else
			paint.setColor(Color.RED);
		
		c.drawCircle(p.getX(), p.getY(), radius*(float).85, paint);
	}
	
	public void drawMe(Canvas c, ColorSelectMenu csm) {
		paint.setColor(Color.BLACK);
		
		c.drawCircle(p.getX(), p.getY(), radius, paint);
		
		paint.setColor(csm.getCurrentColor());

		c.drawCircle(p.getX(), p.getY(), radius*(float).9, paint);
	}

	public Paint getPaint() {
		return paint;
	}
	
	public void setPaint(Paint _p) {
		paint = _p;
	}
	

	public float getX() {
		return p.getX();
	}
	
	public float getR() {
		return radius;
	}
	
	public Vector2D getVel(){
		return velocity;
	}
	
	public Vector2D getDir(){
		return direction;
	}
	
	public void setX(float _x) {
		p.setX(_x);
	}

	public float getY() {
		return p.getY();
	}
	
	public void setY(float _y) {
		p.setY(_y);
	}

	public void checkBoundaryCollision(int display_width, int display_height){
		//left
		if( p.getX() > (display_width - radius) ) {
			p.setX(display_width - radius);
			direction.setX(direction.getX()*-1);
		}
		//right
		if( p.getX() < radius ) {
			p.setX(radius);
			direction.setX(direction.getX()*-1);
		}
		//top
		if( p.getY() < radius ) {
			p.setY(radius);
			direction.setY(direction.getY()*-1);
		}
		//bottom
		if( p.getY() > (display_height - radius) ) {
			p.setY(display_height - radius);
			direction.setY(direction.getY()*-1);
		}
	}
	
	public void updateVelocity() {
		velocity.setX(direction.getX() * MyPhysics.TRAVEL_SPEED);
		velocity.setY(direction.getY() * MyPhysics.TRAVEL_SPEED);
	}
	
	public void updatePosition() {
		p.setX(p.getX()+velocity.getX());
		p.setY(p.getY()+velocity.getY());
	}
	
	public void updateLoc(Canvas c) {
		updateVelocity();
		updatePosition();
		checkBoundaryCollision(c.getWidth(),c.getHeight());
	}

	public void updateLoc() {
		// TODO Auto-generated method stub
		
	}

	public void setScreenNumber(int s) {
		screen = s;
	}
	
	public int getScreenNumber() {
		return screen;
	}
}
